package com.component.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import java.sql.Connection;
import com.component.dao.conexionMySQL;
import com.component.dto.CalendarioDTO;

public class CalendarioDAO {
	private static Logger log = Logger.getLogger(CalendarioDAO.class);	
    //String pkgVar = (AppProperties.getProperty("aplicacion", "PACKAGE"));
	// String rutaFILE = (AppProperties.getProperty("aplicacion", "RUTA_FILE"));
		 
	public List getAllEjecucionesDia() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {

		List listReporte = new ArrayList();
		conexionMySQL connDao = new conexionMySQL();
		Connection conn = connDao.getConnection();	
		String query = "SELECT " +
				" ID_PROC_INSTANCIA," +
				" HORA_EJECUCION," +
				" ID_CALENDARIO," +
				" ORDEN_EJECUCION, " +
				" FECHA_EJECUCION," +				
				" FECHA_MAX, " +
				" HORA_MAX," +
				" USU_MOD," +
				" FEC_MOD, " +
				" ID_ACTIVIDAD" +
				" FROM sacpro.acp_calendario cal" +
				" where cal.orden_ejecucion = 0" +
				" and cal.fecha_ejecucion = curdate()"; //'2011-11-03'";
		try {
			Statement stmt = null;
			stmt = conn.createStatement();
			ResultSet rs = stmt.executeQuery(query);
			while (rs.next()) {
				CalendarioDTO calDTO = new CalendarioDTO();				
				calDTO.setIdProcInstancia(rs.getString(1)); //idProcInstancia	
				calDTO.setHoraEjecucion(rs.getString(2)); //horaEjecucion
				System.out.println("CalendarioDAO.getAllEjecucionesDia, ID ProcInstancia:"+rs.getString(1));
				log.info("Se encuentra tarea para ejecucion ID ProcInstancia:"+rs.getString(1));
				listReporte.add(calDTO);	            	
			}
			rs.close();
			stmt.close();
		} catch (SQLException ex) {
			ex.printStackTrace();
			log.error("Error CalendarioDAO.getAllEjecucionesDia SQLException: " +ex.getMessage());
		} finally {
			connDao.desconecta(conn);
		}
		return listReporte;
	}

}
